#include <fstream>
#include <iostream>
#include <string>
#include <cstdlib>

typedef unsigned int* NodesID;

NodesID fromJava(std::string fileName, int size)
{
    std::ifstream file(fileName.c_str());
	NodesID nodes = new unsigned int[size];
	if(file) {
		for(int i = 0 ; i < size ; i++ ) {
			std::string nodeString;
			getline(file, nodeString);
			nodes[i] = std::atoi(nodeString.c_str());
		}
		file.close();
	}
	else
		std::cerr << "Error while opening " << fileName.c_str() <<" file!" << std::endl;

	return nodes;
}

void toJava(std::string fileName, double** distanceMatrix, int size) {
	std::ofstream file(fileName.c_str());
	if(file) {
		for(int i = 0 ; i < size ; i++ ) {
			for(int j = 0 ; j < size ; j++) {
				file << distanceMatrix[i][j];
				if( j == size - 1 )
					file << std::endl;
				else
					file << ";";
			}
		}
		file.close();
	} else
		std::cerr << "Error while writing " << fileName.c_str() << std::endl;
}

int main(int argc, char **argv)
{
	/*
	int size = 2;
	double** matrix = new double*[size];
	for(int i = 0 ; i < size ; i++ ) {
		matrix[i] = new double[size];
	}
	matrix[0][0] = 1.1; matrix[0][1] = 2.1; matrix[1][0] = 3.1; matrix[1][1] = 4.1;
	toJava("adrien.txt", matrix, size);
	*/
	NodesID array = fromJava("test.txt",4);
	for(int i = 0 ; i < 4 ; i++ ) {
		std::cout << array[i] << std::endl;
	}
	return 0;
}

